package com.cheng.example.excel.easyexcel.poi;

import com.alibaba.excel.EasyExcel;
import com.cheng.example.excel.easyexcel.util.TestFileUtil;
import com.cheng.example.excel.easyexcel.util.util.ExcelUtil;
import com.cheng.example.util.VmUtil;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


@Ignore
public class TestExcel01 {

    /**
     * 导出excle
     * 单个Sheet导出
     * 无模型映射导出
     */
    @Test
    public void excelExport01() {
        String filePath = TestFileUtil.getPath() + "demo" + File.separator + "exportj.xlsx";
        System.out.println(filePath);
        List<List<Object>> data = new ArrayList<>();
        data.add(Arrays.asList("111", "222", "333"));
        data.add(Arrays.asList("111", "222", "333"));
        data.add(Arrays.asList("111", "222", "333"));
        List<String> head = Arrays.asList("表头1", "表头2", "表头3");
        ExcelUtil.writeBySimple(filePath, data, head);
    }

    /**
     * 导入excel
     */
    @Test
    public void excelImport01() {
//        String filePath = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
        VmUtil.printMemory();
        File file = new File("E:\\RATE_ERP_CASHVALUE72003.xlsx");
        String filePath = file.getPath();
        long start = System.currentTimeMillis();
//        long end = System.currentTimeMillis();
//        System.out.println(end - start);
//        List<Object> objects = ExcelUtil.readLessThan1000Row(filePath);
//        List<Object> objects = ExcelUtil.readMoreThan1000Row(filePath);

        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 同步读取会自动finish
        List<Map<String, String>> listMap = EasyExcel.read(filePath).sheet().doReadSync();
        System.out.println("集合个数\t"+listMap.size());
        System.out.println(listMap);
        // 虚拟机级内存情况查询
        System.out.println("=====");
        VmUtil.printMemory();
        System.out.println("=====");
//        List<Object> cloneOb = new ArrayList<>();
//        BeanUtils.copyProperties(objects, cloneOb);
//        VmUtil.printMemory();
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        System.out.println(listMap.size());

//        String filePath = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
//        //第一个1代表sheet1, 第二个1代表从第几行开始读取数据，行号最小值为0
//        Sheet sheet = new Sheet(1, 1);
//        List<Object> objects = ExcelUtil.readLessThan1000RowBySheet(filePath,sheet);
//        System.out.println(objects);
//        System.out.println(StringUtils.hasText("\n  \t"));
    }

    /**
     * 导入excel
     */
    @Test
    public void excelImport02() {
//        String filePath = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
        VmUtil.printMemory();
        File file = new File("E:\\RATE_ERP_CASHVALUE72003.xlsx");
        String filePath = file.getPath();
        long start = System.currentTimeMillis();
//        long end = System.currentTimeMillis();
//        System.out.println(end - start);
//        List<Object> objects = ExcelUtil.readLessThan1000Row(filePath);
//        List<Object> objects = ExcelUtil.readMoreThan1000Row(filePath);

        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 同步读取会自动finish
        List<Map<String, String>> listMap = EasyExcel.read(filePath).sheet().doReadSync();
        System.out.println("集合个数\t"+listMap.size());
        System.out.println(listMap);
        // 虚拟机级内存情况查询
        System.out.println("=====");
        VmUtil.printMemory();
        System.out.println("=====");
//        List<Object> cloneOb = new ArrayList<>();
//        BeanUtils.copyProperties(objects, cloneOb);
//        VmUtil.printMemory();
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        System.out.println(listMap.size());

//        String filePath = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
//        //第一个1代表sheet1, 第二个1代表从第几行开始读取数据，行号最小值为0
//        Sheet sheet = new Sheet(1, 1);
////        List<Object> objects = ExcelUtil.readLessThan1000RowBySheet(filePath,sheet);
////        System.out.println(objects);
//        System.out.println(StringUtils.hasText("\n  \t"));
    }
}